package com.sdp.flow;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class DbGenerator {

	/**
	 * 一对一数据模型，生成方法
	 * @param args
	 */
	public static void main(String[] args) {
		AutoGenerator generator = new AutoGenerator();
		// set freemarker engine
		generator.setTemplateEngine(new FreemarkerTemplateEngine());
		
		GlobalConfig globalConfig = new GlobalConfig();
		globalConfig.setOutputDir(System.getProperty("user.dir") + "/src/main/java");
		globalConfig.setAuthor("qcy");
		globalConfig.setOpen(false);
		globalConfig.setFileOverride(true);
		globalConfig.setActiveRecord(true);
		generator.setGlobalConfig(globalConfig);
		
		  // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://47.105.178.170:3306/smart_camp?useUnicode=true&characterEncoding=UTF8&allowMultiQueries=true&serverTimezone=PRC&useSSL=false");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("111111");
        generator.setDataSource(dsc);
		
        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.sdp.flow.db");
        pc.setEntity("entity");
        pc.setMapper("mapper");
        pc.setXml("mapper.xml");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setController("web");
        generator.setPackageInfo(pc);
        
        
        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        //strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        strategy.setEntityLombokModel(true);
        strategy.setSkipView(true);
        strategy.setEntityTableFieldAnnotationEnable(true);
        //"act_re_model", "act_hi_procinst", "act_re_procdef"
        strategy.setInclude("act_hi_actinst");
        generator.setStrategy(strategy);
        
        generator.execute();
        
		System.out.println(System.getProperty("user.dir"));

	}
}
